class WebWrappersController < ApplicationController
  before_filter :authenticate_member
  before_filter :authenticate_admin, :except => ['show']
  # GET /web_wrappers
  # GET /web_wrappers.xml
  def index
    @web_wrappers = WebWrapper.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @web_wrappers }
    end
  end

  # GET /web_wrappers/1
  # GET /web_wrappers/1.xml
  def show
    @web_wrapper = WebWrapper.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @web_wrapper }
    end
  end

  def test
    if web_wrapper = WebWrapper.find(params[:id])
      render :text =>  web_wrapper.wrap_source_url(web_wrapper.test_url), :layout => false
    else
      render :text => "Le webwrapper n'a pu etre trouvé!"
    end
  end

  # GET /web_wrappers/new
  # GET /web_wrappers/new.xml
  def new
    @web_wrapper = WebWrapper.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @web_wrapper }
    end
  end

  # GET /web_wrappers/1/edit
  def edit
    @web_wrapper = WebWrapper.find(params[:id])
  end

  # POST /web_wrappers
  # POST /web_wrappers.xml
  def create
    @web_wrapper = WebWrapper.new(params[:web_wrapper])

    respond_to do |format|
      if @web_wrapper.save
        flash[:notice] = 'WebWrapper was successfully created.'
        format.html { redirect_to(@web_wrapper) }
        format.xml  { render :xml => @web_wrapper, :status => :created, :location => @web_wrapper }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @web_wrapper.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /web_wrappers/1
  # PUT /web_wrappers/1.xml
  def update
    @web_wrapper = WebWrapper.find(params[:id])

    respond_to do |format|
      if @web_wrapper.update_attributes(params[:web_wrapper])
        flash[:notice] = 'WebWrapper was successfully updated.'
        format.html { redirect_to(@web_wrapper) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @web_wrapper.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /web_wrappers/1
  # DELETE /web_wrappers/1.xml
  def destroy
    @web_wrapper = WebWrapper.find(params[:id])
    @web_wrapper.destroy

    respond_to do |format|
      format.html { redirect_to(web_wrappers_url) }
      format.xml  { head :ok }
    end
  end
end
